<template>
  <div class="tab-bar-item" @click="itemClick" :style="isAction">
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-action"></slot>
    </div>
    <div>
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>

  export default {
    name: "TabBarItem",
    props:{
      path:String,
      backgrounds:{
        type: String,
        default: 'rgba(100,100,100,.1)'
      },
      fontColor:{
        type: String,
        default: 'black'
      }
    },
    computed:{
      isActive(){
        return this.$route.path.indexOf(this.path) !== -1
      },
      isAction(){
        return this.isActive?{background:this.backgrounds,color:this.fontColor}:{}
      }
    },
    methods:{
      itemClick(){
        this.$router.replace(this.path).catch(err => {})
      }
    }

  }
</script>

<style scoped>
  .tab-bar-item{
    flex: 1;
  }
  .tab-bar-item img{
    width: 24px;
    height: 24px;
    margin-top: 2px;
    margin-bottom: -3px;
  }
</style>
